package com.quanyue.mechanics.complex.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.mechanics.complex.service.MenusService;
import com.quanyue.mechanics.domain.entity.Menus;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "商品分类")
@RestController
@RequestMapping("/api")
public class MenusController {
    @Autowired
    private MenusService menusService;

    @ApiOperation(value = "添加分类")
    @PostMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Menus> addMenus(@RequestBody Menus menus) {
        return ServiceResult.success(menusService.addMenus(menus));
    }

    @ApiOperation(value = "修改分类")
    @PutMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> updateMenus(@RequestBody Menus menus) {
        menusService.updateMenus(menus);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除分类")
    @DeleteMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> deleteMenus(@RequestParam("id") Integer id) {
        menusService.deleteMenus(id);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "分类列表")
    @GetMapping(value = "/menus", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <List <Menus>> findMenus() {
        return ServiceResult.success(menusService.findMenus());
    }

}
